<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>在线学院</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layui/css/layui.css" media="all">
</head>
<body>

<form class="layui-form" lay-filter="college_list_form" id="college_list_form"
     style="padding: 20px 30px 0 0;">
    <div class="layui-form-item">
        <label class="layui-form-label">文章类型</label>
        <div class="layui-input-inline">
            <select name="sharetype" id="sharetype" lay-filter="sharetype">
                <option value=""></option>
                <option  value="1">拓客技巧</option>
                <option  value="2">视频分享</option>
                <option  value="3">公司介绍</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">文章标题</label>
        <div class="layui-input-inline">
            <input type="text" name="title" lay-verify="required" id="title" placeholder="输入文章标题" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-hide" id="video">
        <label class="layui-form-label">视频播放链接</label>
        <div class="layui-input-inline">
            <input type="text" name="videoUrl"  id="videoUrl" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item" id="detail">
        <label class="layui-form-label">文章详情</label>
        <div class="layui-input-inline">
            <textarea name="particulars"  id="particulars" style="width: 600px; height: 150px;" autocomplete="off"
                      class="layui-textarea">
            </textarea>
        </div>
    </div>

    <div class="layui-form-item layui-hide" id="videointro">
        <label class="layui-form-label">视频简介</label>
        <div class="layui-input-inline">
            <textarea name="videointro" style="width: 400px; height: 50px;" autocomplete="off"
                      class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item layui-hide">
        <input type="button" lay-submit lay-filter="layuiadmin-app-form-submit" id="layuiadmin-app-form-submit"
               value="确认添加">
        <input type="button" lay-submit lay-filter="layuiadmin-app-form-edit" id="layuiadmin-app-form-edit"
               value="确认编辑">
    </div>
</form>

<script src="/layui/layui.js"></script>
<script src="kindeditor/kindeditor-all.js"></script>
<script src="kindeditor/lang/zh-CN.js"></script>
<script>

    KindEditor.ready(function (K) {
        window.KE = K.create('#particulars', {
            items: ['source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
                'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
                'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
                'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
                'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
                'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage',
                'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
                'anchor', 'link', 'unlink', '|', 'about'],
            allowFileManager: true,
            minHeight:400,
            filePostName: 'file',//跟服务端参数对应
            uploadJson: "/kindeditor/fileUpload",
            fileManagerJson: "/kindeditor/fileManager",//指定浏览远程图片的服务器端程序
            afterCreate : function() {
                let self = this;
                K.ctrl(document, 13, function() {
                    self.sync();
                    document.forms['activity_form'].submit();
                });
                K.ctrl(self.edit.doc, 13, function() {
                    self.sync();
                    document.forms['activity_form'].submit();
                });
            },
            afterUpload: function (url) {
                // console.log(url);
            }
        });
    });
    layui.config({
        base: '/layui/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form'], function () {
        let $ = layui.$, form = layui.form;
        let user = layui.data("user");

        function GetQueryString(name) {
            let reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
            let r = window.location.search.substr(1).match(reg);
            if(r!=null)return  unescape(r[2]); return null;
        }
        let id = GetQueryString("id");
        $.get('get_online_content',{id:id},function (resp) {
            KE.html(resp);
        })
        //监听提交
        form.on('submit(layuiadmin-app-form-submit)', function (data) {
            var field = data.field; //获取提交的字段
            field.particulars = KE.html();
            field.login_name = user.user_id;
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引

            //提交 Ajax 成功后，关闭当前弹层并重载表格
            //$.ajax({});
            $.post('addShareContext',field,function (resp) {
                if(resp.code == "0"){
                    layer.msg(resp.msg);
                    parent.layui.table.reload('sharelist'); //重载表格
                    parent.layer.close(index); //再执行关闭
                }else{
                    layer.msg(resp.msg);
                }
            })
        });

        form.on('submit(layuiadmin-app-form-edit)', function (data) {
            var field =data.field;
            field.particulars = KE.html();
            field.id = id;
            var index = parent.layer.getFrameIndex(window.name);
            $.post('modifyShareContext',field,function (resp) {
                if(resp.code == "0"){
                    layer.msg(resp.msg);
                    parent.layui.table.reload('sharelist'); //重载表格
                    // parent.layer.close(index); //再执行关闭
                }else{
                    layer.msg(resp.msg);
                }
            })
        });

        form.on('select(sharetype)', function(data){
           if(data.value == "2"){
               $('#video').removeClass('layui-hide');
               $('#detail').addClass('layui-hide')
               $('#videointro').removeClass('layui-hide');
           }else{
               $('#video').addClass('layui-hide');
               $('#detail').removeClass('layui-hide');
               $('#videointro').addClass('layui-hide');
           }
        });
    })
</script>
</body>
</html>